<script setup name="deviceList">
import { GetListAPI } from '@/api/device/spotCheck/project.js'

const { proxy } = getCurrentInstance()

// const { sys_material_type } = proxy.useDict('sys_material_type')
const props = defineProps({
  isShow: {
    type: Boolean,
    default: false
  },

  title: {
    type: String,
    default: '物料'
  },
  // 是否单选
  bdb: {
    type: Boolean,
    default: false
  }
})

const emit = defineEmits(['selectsubmit', 'preservation', 'cancel', 'reset'])

const loading = ref(false)

const typeSelect = ref([])

// 查询条件
const query = reactive({
  pageNum: 1,
  pageSize: 10,
  materialName: '', // 名称
  materialCode: '', // 编码
  materialType: '', // 物料类别
  type: '' // 类别
})

const handleSelect = ref({ id: '' })
const handleSelects = ref([])
const TableData = ref([])
const total = ref(0)

// 勾选数据
const handleSelectionChange = row => {
  handleSelect.value = row
}

// 勾选数据
const handleSelectionChanges = row => {
  handleSelects.value = row
}

// 是否禁用 保存
const d = computed(() => {
  if (props.bdb) {
    return handleSelect.value?.id ? false : true
  } else {
    return handleSelects.value.length > 0 ? false : true
  }
})

// 提交
const preservation = () => {
  if (props.bdb) {
    emit('preservation', handleSelect.value)
  } else {
    emit('preservation', handleSelects.value)
  }
}

// 重置
const reset = () => {
  for (let key in query) {
    query[key] = ''
  }

  getList()
}

// 查询
const getList = async () => {
  loading.value = true
  try {
    const res = await GetListAPI(query)
    total.value = res.total
    TableData.value = res.rows
  } catch {
  } finally {
  }
  loading.value = false
}
getList()
</script>
<template>
  <div class="app-container">
    <!-- 查询条件 -->
    <p-dialog v-model="props.isShow" title="设备信息" @close="emit('cancel')" width="50%">
      <template #body>
        <el-form :inline="true" label-width="100px">
          <el-form-item label="设备编码">
            <el-input clearable v-model.trim="query.maintenanceProjectCode" placeholder="请输入设备编码" />
          </el-form-item>
          <el-form-item label="设备名称">
            <el-input clearable v-model.trim="query.maintenanceProjectName" placeholder="请输入设备名称" />
          </el-form-item>
        </el-form>

        <el-divider />
        <el-table
          stripe
          v-if="!loading"
          border
          :loading="loading"
          :data="TableData"
          highlight-current-row
          @current-change="handleSelectionChange"
          @selection-change="handleSelectionChanges"
        >
          <el-table-column label="序号" width="80" type="index" />
          <el-table-column width="80" v-if="props.bdb">
            <template #default="scope">
              <el-radio-group v-model="handleSelect.id">
                <el-radio :label="scope.row.id" size="large">&nbsp;</el-radio>
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column v-else type="selection" width="55" align="center" fixed="left" />
          <el-table-column
            label="点检部位"
            prop="pointTestPosition"
            width="auto"
            align="center"
            show-overflow-tooltip
          />
          <el-table-column
            label="点检方式"
            prop="pointTestModeDict"
            width="auto"
            align="center"
            show-overflow-tooltip
          />
          <el-table-column label="点检内容" prop="pointTestContent" width="auto" align="center" show-overflow-tooltip />
          <el-table-column
            label="检验标准"
            prop="inspectionStandard"
            width="auto"
            align="center"
            show-overflow-tooltip
          />
          <el-table-column
            label="检验类型"
            prop="inspectionTypeDict"
            width="auto"
            align="center"
            show-overflow-tooltip
          />
          <el-table-column label="判定结果项" prop="decisionResult" width="auto" align="center" show-overflow-tooltip />
          <el-table-column label="标准工时" prop="workingHour" width="auto" align="center" show-overflow-tooltip />
          <el-table-column label="备注" prop="remark" width="auto" align="center" show-overflow-tooltip />
        </el-table>
        <div class="pagination">
          <pagination
            v-show="total > 0"
            :total="total"
            v-model:page="query.pageNum"
            v-model:limit="query.pageSize"
            @pagination="Get"
          />
        </div>
        <!-- 按钮 -->
        <div>
          <el-row class="Btn">
            <el-button type="primary" @click="getList">查询列表</el-button>
            <el-button type="info" @click="reset">重置</el-button>
            <el-button type="success" @click="preservation" :disabled="d">保存</el-button>
            <el-button type="info" @click="emit('cancel')">取消</el-button>
          </el-row>
        </div>
      </template>
    </p-dialog>
  </div>
</template>

<style scoped lang="scss">
.Btn {
  margin-top: 10px;
  float: right;
}
</style>
